import os
import sys


def isFIle(file):
    if os.path.exists(file):
        message = '文件存在执行修改'
        exist = True
    else:
        message = '文件不存在'
        exist = False
    print(message)
    return exist


def getCurrentDirApk():
    for dir in os.walk(os.curdir):
        for filename in dir[2]:
            if os.path.splitext(filename)[1] == '.apk':
                return filename


def name():
    value = input('请输入:kfzs.properties文件路径:')
    game = input('请输入需要修改的包名:')
    if isFIle(value):
        f = open(value, 'r+')
        flist = f.readlines()
        flist[0] = 'game_package_name=' + game + '\n'
        f = open(value, 'w+')
        f.writelines(flist)
        f.close()
        print("操作成功")

    if len(sys.argv) == 1:
        apk = getCurrentDirApk()
    else:
        apk = sys.argv[1]
    if not apk:
        print('没有找到APK文件!!!')
    print(apk)


if __name__ == '__main__':
    name()
